package com.cloudcc.mobile.manager;

import android.content.Context;

import com.cloudcc.cloudframe.CApplication;
import com.cloudcc.mobile.AppConfig;
import com.cloudcc.mobile.util.PreferenceUtils;

/**
 * 配置信息管理
 * 
 * @author wangzhiqiang
 * @date 2015-7-24 下午2:52:50
 * 
 */
public class ConfigManager {

	private static ConfigManager instance;
	private Context mContext;
	private final String XML;

	private ConfigManager(Context context) {
		super();
		this.mContext = context;
		XML = AppConfig.XML_CONFIG + "_"
				+ UserManager.getManager().getUser().userId;
	}

	public static ConfigManager getInstance() {
		if (instance == null) {
			instance = new ConfigManager(CApplication.getApp());
		}
		return instance;
	}

	/**
	 * 是否开启定位模式
	 * 
	 * @param loaction
	 */
	public void setlocation(boolean loaction) {
		PreferenceUtils.commitBoolean(mContext, XML, IKey.LOCATION_ISLOCATION,
				loaction);
	}

	/**
	 * 是否是开启定位模式
	 * 
	 * @return 默认返回false
	 */
	public boolean isAllowLocation() {
		return PreferenceUtils.getBoolean(mContext, XML,
				IKey.LOCATION_ISLOCATION, AppConfig.LOACL_ISLOACL);
	}

	/**
	 * 设置 定位速率
	 * 
	 * @param time
	 *            默认看cconfig配置
	 */
	public void setLocationTime(int time) {
		PreferenceUtils.commitInt(mContext, XML, IKey.LOCATION_TIME, time);
	}

	/**
	 * 获得 定位频率（精准度）
	 * 
	 * @return
	 */
	public int getLocationTime() {
		return PreferenceUtils.getInt(mContext, XML, IKey.LOCATION_TIME,
				AppConfig.LOCATION_TIME);
	}

	/**
	 * 是否开启推送
	 * 
	 * @param loaction
	 */
	public void setPush(boolean push) {
		PreferenceUtils.commitBoolean(mContext, XML, IKey.PUSH_ISPUSH, push);
	}

	/**
	 * 是否允许消息推送
	 * 
	 */
	public boolean isAllowPush() {
		return PreferenceUtils.getBoolean(mContext, XML, IKey.PUSH_ISPUSH,
				AppConfig.PUSH_ISPUSH);
	}

	/**
	 * 是否开启消息推送 声音提醒模式
	 * 
	 * @param allow
	 */
	public void setAllowPushSound(boolean allow) {
		PreferenceUtils.commitBoolean(mContext, XML, IKey.PUSH_SOUND, allow);
	}

	/**
	 * 是否是开启定位模式
	 * 
	 * @return 默认返回true
	 */
	public boolean isAllowPushSound() {
		return PreferenceUtils.getBoolean(mContext, XML, IKey.PUSH_SOUND,
				AppConfig.PUSH_SOUND);
	}

	/**
	 * 是否开启消息推送 声音提醒模式
	 * 
	 * @param allow
	 */
	public void setAllowPushVibrate(boolean allow) {
		PreferenceUtils.commitBoolean(mContext, XML, IKey.PUSH_VIBRATE, allow);
	}

	/**
	 * 是否是开启定位模式
	 * 
	 * @return 默认返回true
	 */
	public boolean isAllowPushVibrate() {
		return PreferenceUtils.getBoolean(mContext, XML, IKey.PUSH_VIBRATE,
				AppConfig.PUSH_VIBRATE);
	}

	public interface IKey {

		/**
		 * 是否开启定位
		 */
		String LOCATION_ISLOCATION = "location.islocation";
		/**
		 * 定位频率
		 */
		String LOCATION_TIME = "location.time";

		/**
		 * 推送。是否开启推送
		 */
		String PUSH_ISPUSH = "push.ispush";

		/**
		 * 推送。是否有声音支持
		 */
		String PUSH_SOUND = "push.sound";

		/**
		 * 推送。震动
		 */
		String PUSH_VIBRATE = "push.vibrate";

	}
}
